package com.rjet.view_demo1;

import android.content.Context;
import android.os.Handler;
import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;

import razerdp.basepopup.BasePopupWindow;

public class DemoPopup extends BasePopupWindow {

    ArrayList<DemoEntity> demoEntities = new ArrayList<>();

    interface CustomOperationListener{

       void dismiss();
    }


    public CustomOperationListener customOperationListener;

    public void setCustomOperationListener(CustomOperationListener customOperationListener) {
        this.customOperationListener = customOperationListener;
    }

    public DemoPopup(Context context) {
        super(context);

        View v = createPopupById(R.layout.pop_view);

        for (int i = 0; i < 100; i++) {
            DemoEntity demoEntity = DemoEntity.builder().name("name" + (i + 1))
                    .id(i)
                    .age((i + 1))
                    .build();
            demoEntities.add(demoEntity);
        }

        RecyclerView rv = (RecyclerView)v.findViewById(R.id.news_list_recyclerView);
        DemoAdapter demoAdapter = new DemoAdapter(R.layout.demo_layout, demoEntities);
        rv.setLayoutManager(new LinearLayoutManager(context));
        rv.setAdapter(demoAdapter);
        demoAdapter.setNewData(demoEntities);

        demoAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                Log.d("czy", "onItemClick: " + position);
            }
        });

        v.findViewById(R.id.pop_view_container).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("czy", "onClick: ..");
                customOperationListener.dismiss();
            }
        });

        setContentView(v);
    }
}
